from math import pi

R = RIGHT = 0
U = UP = 1
L = LEFT = 2
D = DOWN = 3
ORDERED = (R, U, L, D)

DX = (+1, 0, -1, 0)
DY = (0, +1, 0, -1)
DELTA = zip(DX, DY)

FLOAT_DX = map(float, DX)
FLOAT_DY = map(float, DY)
FLOAT_DELTA = zip(FLOAT_DX, FLOAT_DY)

ANGLE = (0.0, pi/2.0, pi, pi*3.0/2.0)
NAME = ("right", "up", "left", "down")
CHAR = ("R", "U", "L", "D")


def from_delta(dx, dy):
    if dx != 0 and dy != 0:
        raise ValueError("invalid direction")
    if dx > 0:
        return RIGHT
    elif dx < 0:
        return LEFT
    elif dy > 0:
        return UP
    elif dy < 0:
        return DOWN
